//
//  CouponView.m
//  Cat
//
//  Created by lushitong on 2018/12/18.
//  Copyright © 2018年 lushitong. All rights reserved.
//

#import "CouponView.h"

@interface CouponView()

@property (nonatomic, strong) UIImageView *operImageView;
@property (nonatomic, strong) UILabel *juanLabel;
@property (nonatomic, strong) UILabel *couponLabel;

@end

@implementation CouponView

- (void)setMoneyNumber:(NSNumber *)moneyNumber {
	_moneyNumber = moneyNumber;
	_couponLabel.text = [NSString stringWithFormat:@"%.0f元",[moneyNumber.stringValue validateString] ? moneyNumber.floatValue : 0.0];
}

+ (CGSize)getSizeWithMoneyNumber:(NSNumber *)moneyNumber {
	return CGSizeMake(kQKFitModuleDecimal(48.0), kQKFitModuleDecimal(19.0));
}

- (instancetype)initWithFrame:(CGRect)frame {
	self = [super initWithFrame:frame];
	if (self) {
		[self addAllSubviews];
	}
	return self;
}

- (void)addAllSubviews {
	[self addSubview:self.operImageView];
	[self.operImageView addSubview:self.couponLabel];
	[self.operImageView addSubview:self.juanLabel];
	[self.operImageView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.edges.equalTo(self);
	}];
	
	[self.juanLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.centerY.equalTo(self.operImageView.mas_centerY);
		make.left.equalTo(self.operImageView.mas_left).offset(kQKFitModuleDecimal(2.0));
	}];
	
	[self.couponLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.centerY.equalTo(self.operImageView.mas_centerY);
		make.left.equalTo(self.operImageView.mas_left).offset(kQKFitModuleDecimal(19.0));
	}];
}

#pragma mark----- lazy init -----

- (UIImageView *)operImageView {
	if (!_operImageView) {
		_operImageView = [[UIImageView alloc] init];
		_operImageView.image = [UIImage imageNamed:@"fl_juan_pic"];
	}
	return _operImageView;
}

- (UILabel *)juanLabel {
	if (!_juanLabel) {
		_juanLabel = [UILabel labelWithFont:[UIFont systemFontOfSize:kQKFitFont(10)] textColor:[UIColor whiteColor]];
		_juanLabel.text = @"券";
	}
	return _juanLabel;
}

- (UILabel *)couponLabel {
	if (!_couponLabel) {
		_couponLabel = [UILabel labelWithFont:[UIFont boldSystemFontOfSize:kQKFitFont(10.0)] textColor:[UIColor whiteColor]];
		_couponLabel.textAlignment = NSTextAlignmentCenter;
	}
	return _couponLabel;
}

@end
